<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // Promise虽然比回调更好，但是不是最好的，因为依然存在回调
    // 所以就诞生了Async函数
    function getData1 () {
      return new Promise((resolve, reject) => {
        const data = 'tom'
        setTimeout(() => {
          resolve(data)
        }, 1000)
      })
    }
    function getData2 () {
      return new Promise((resolve, reject) => {
        const data = 'jerry'
        setTimeout(() => {
          resolve(data)
        }, 2000)
      })
    }
    function getData3 () {
      return new Promise((resolve, reject) => {
        const data = 'spike'
        setTimeout(() => {
          resolve(data)
        }, 3000)
      })
    }

    async function getResult () {
      const ret3 = await getData3()
      const ret1 = await getData1()
      const ret2 = await getData2()
      // 6秒后才会打印结果
      console.log(ret3, ret1, ret2)
    }
    getResult()
  </script>
</body>
</html>
